#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "gui_guider.h"
#include "device.h"
#include "inv_mpu.h"

extern TaskHandle_t mpuTaskHandle;

void mpuTask(void *pvParameter) {

    uint8_t t = 0;
    float pitch, roll, yaw;     //欧拉角
    int16_t aacx, aacy, aacz;   //加速度传感器原始数据
    int16_t gyrox,gyroy,gyroz;	//陀螺仪原始数据
    int16_t temp;
    char str[10];

    MY_MPU6050_Init();
    vTaskSuspend(mpuTaskHandle);    /* 挂起任务 */

    while(1)
    {
        if(mpu_dmp_get_data(&pitch, &roll, &yaw) == 0)
        {
            temp=MPU_Get_Temperature();	//得到温度值
            MPU_Get_Accelerometer(&aacx, &aacy, &aacz);	//得到加速度传感器数据
			MPU_Get_Gyroscope(&gyrox, &gyroy, &gyroz);	//得到陀螺仪数据

            if((t % 10) == 0)
            {
                //温度temperature
                printf("the temperature is %d.%d\n", temp/100,temp%10);  
                sprintf(str,"%d",temp/100);
                lv_label_set_text(guider_ui.Gyro_temp_value, str);

                //俯仰角pitch
                temp = pitch * 10;
                printf("the pitch is %d.%d\n", temp/10,temp%10);
                sprintf(str,"%d",temp/10);
                lv_label_set_text(guider_ui.Gyro_pitch_value, str);

                //横滚角roll
                temp = roll * 10;
                printf("the roll is %d.%d\n", temp/10,temp%10);
                sprintf(str,"%d",temp/10);
                lv_label_set_text(guider_ui.Gyro_roll_value, str);

                //航向角yaw
                temp = yaw * 10;
                printf("the yaw is %d.%d\n", temp/10,temp%10);
                sprintf(str,"%d",temp/10);
                lv_label_set_text(guider_ui.Gyro_yaw_value, str);

                t = 0;
                printf("\n");
                vTaskDelay(50 / portTICK_PERIOD_MS); 
           }
        }
        t++;
    }
}







